package com.Policing.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @作者(author): WR
 * @创建时间(date): 2020/9/2
 */
public class ThreadPool {
    //线程池接口类
    private volatile static ExecutorService service;

    /*    序号	名称	类型	含义
    1	corePoolSize	int	核心线程池大小
    2	maximumPoolSize	int	最大线程池大小
    3	keepAliveTime	long	线程最大空闲时间
    4	unit	TimeUnit	时间单位
    5	workQueue	BlockingQueue<Runnable>	线程等待队列
    6	threadFactory	ThreadFactory	线程创建工厂
    7	handler	RejectedExecutionHandler	拒绝策略*/

    private static ExecutorService getService() {
        if (service == null) {
            synchronized (ThreadPool.class) {
                if (service == null) {
                    service = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5 * 2));
                }
            }
        }
        return service;
    }

    //线程池执行线程
    public static void runThread(Runnable runnable) {
        getService().execute(runnable);
    }
}
